package com.example.jl.pickpiclibrary.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.example.jl.pickpiclibrary.utils.ImageLoader;

import java.util.ArrayList;

/**
 * Created by JL on 6/3/15.
 */
public class GridAdapter extends BaseAdapter {
    ViewGroup.LayoutParams params = new AbsListView.LayoutParams(100, 100);
    private static final int SHOW_BIG = 1;
    private Context context;
    private ArrayList<String> selectedPicture;

    public GridAdapter(Context context, ArrayList<String> selectedPicture) {
        this.context = context;
        this.selectedPicture = selectedPicture;

    }

    @Override
    public int getCount() {
        return selectedPicture.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = new ImageView(context);
            ((ImageView) convertView).setScaleType(ImageView.ScaleType.CENTER_CROP);
            convertView.setLayoutParams(params);
        }
        ImageLoader.getInstance(3, ImageLoader.Type.LIFO).loadImage(selectedPicture.get(position),
                (ImageView) convertView);
//        convertView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                ((Activity) context).startActivityForResult(new Intent(context, com.example.jl.pickpiclibrary.activity.BigPhotoShowActivity.class)
//                        .putExtra("position", position).putStringArrayListExtra("photos", selectedPicture), SHOW_BIG);
//            }
//        });
        return convertView;
    }


}
